import time

from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.service import Service as FirefoxService
# 自动下载对应的驱动
from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager

driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))
#最大化窗口
driver.maximize_window()
driver.get("https://www.baidu.com/")
# 通过ID定位
driver.find_element(By.CSS_SELECTOR, '#kw').send_keys("dd")
driver.find_element(By.CSS_SELECTOR, '#su').click()
# 通过 className定位
driver.find_element(By.CSS_SELECTOR, '.nav-search-input').send_keys()
#根据name定位

driver.find_element(By.CSS_SELECTOR, "[name='id']").send_keys()
#根据标签定位
driver.find_element(By.CSS_SELECTOR, "a[href='http://image.baidu.com']").send_keys()
driver.find_element(By.CSS_SELECTOR, "div#s-top-left>a:nth-child(3)").click()


time.sleep(10)

driver.close();